from poker_bot.core.models.dto import UserDTO
from poker_bot.core.models.dto.user import UserWithDepositsDTO
from poker_bot.database.models import User
from poker_bot.domain.user import UserEntity


def convert_db_model_to_user_dto(user: User) -> UserDTO:
    return UserDTO(
        id=user.id,
        role=user.role,
        username=user.username,
        telegram_id=user.telegram_id,
        referrer_id=user.referrer_id,
        selected_account_id=user.selected_account_id,
        is_subscribed=user.is_subscribed,
        lang_code=user.lang_code,
        created_at=user.created_at,
    )


def convert_db_model_to_user_with_deposits_dto(user: User) -> UserWithDepositsDTO:
    return UserWithDepositsDTO(
        id=user.id,
        role=user.role,
        username=user.username,
        referrer_id=user.referrer_id,
        deposits_count=len(user.deposits),
        selected_account_id=user.selected_account_id,
        telegram_id=user.telegram_id,
        is_subscribed=user.is_subscribed,
        lang_code=user.lang_code,
        created_at=user.created_at,
    )


def convert_db_model_to_user_entity(user: User) -> UserEntity:
    return UserEntity(
        id=user.id,
        role=user.role,
        username=user.username,
        telegram_id=user.telegram_id,
        referrer_id=user.referrer_id,
        selected_account_id=user.selected_account_id,
        is_subscribed=user.is_subscribed,
        lang_code=user.lang_code,
    )


def convert_user_entity_to_db_model(user: UserEntity) -> User:
    return User(
        id=user.id,
        role=user.role,
        username=user.username,
        telegram_id=user.telegram_id,
        referrer_id=user.referrer_id,
        selected_account_id=user.selected_account_id,
        is_subscribed=user.is_subscribed,
        lang_code=user.lang_code,
    )
